import java.util.*;

public class Main {
    public static void tree2str(MyTrue.Node root,StringBuilder stringBuilder) {
        if(root==null) return;
stringBuilder.append(root.value);
        if (root.left != null) {
            stringBuilder.append("(");
            tree2str(root.left,stringBuilder);
            stringBuilder.append(")");
        }

        if (root.right != null) {
            stringBuilder.append("(");
            tree2str(root.right,stringBuilder);
            stringBuilder.append(")");
        }
        else return;
    }

    public static void main(String[] args) {
        MyTrue myTrue=new MyTrue();
        MyTrue.Node root=myTrue.inti();
        StringBuilder stringBuilder=new StringBuilder();
        tree2str(root,stringBuilder);
        System.out.println(stringBuilder.toString());
       Scanner scanner=new Scanner(System.in);
       String s="afsa";
        HashMap<Integer,Integer> hashMap=new HashMap<>();
    }



    static   int perIndexof=0;
    public static MyTrue.Node builderNode(char[] perOrder,char[] inOrder,int begin,int last){
        if(begin>last) return null;
        MyTrue.Node root=new MyTrue.Node(perOrder[perIndexof]);
        int find=findNodeIndeof(inOrder,begin ,last,perOrder[perIndexof]);
        perIndexof++;
        root.left=builderNode(perOrder,inOrder,begin,find-1);
        root.right=builderNode(perOrder,inOrder,find+1,last);
        return  root;
    }

    public static int findNodeIndeof(char[] inOrder,int begin,int last,char key){
        for(int i=begin;i<=last;i++){
            if(inOrder[i]==key) return i;
        }
         return -1;
    }



    public static void main66(String[] args) {
        MyTrue myTrue=new MyTrue();
        MyTrue.Node root=myTrue.inti();
        char[] perOrder="abdehicfg".toCharArray();
        char[] inOrder="dbheiafcg".toCharArray();
         MyTrue.Node root1=builderNode(perOrder,inOrder,0,inOrder.length-1);
         myTrue.perOrder(root);
         System.out.println();
        myTrue.perOrder(root1);

    }
    public static void main11(String[] args) {
        MyTrue myTrue=new MyTrue();
        MyTrue.Node root=myTrue.inti();
        Queue<MyTrue.Node> queue=new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()){
            MyTrue.Node node=queue.poll();
            System.out.print(node.value+" ");
            if(node.left!=null) queue.offer(node.left);
            if(node.right!=null) queue.offer(node.right);
        }
    }

    public static void main3(String[] args) throws NullPointerException{
        MyTrue myTrue=new MyTrue();
        MyTrue.Node root=myTrue.inti();
        myTrue.perOrder(root);
//        System.out.println(myTrue.getLeveNodeCount(root,3));
//        System.out.println(myTrue.getHeight(root));
//        try{
//            System.out.println(myTrue.find(root, 'l').value);
//        } catch (NullPointerException e) {
//            System.out.println("null");
//        }finally {
//            System.out.println("hhh");
//        }
    }


    public static void main1(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] b1=new int[2];
        int[] b2=new int[2];
        b1[0]=0;
        b1[1]=0;
            b2[0]=scanner.nextInt();
            b2[1]=scanner.nextInt();
        int s=0;
        for(int i=0;i<n;i++){
            int[] a1=new int[2];
            int[] a2=new int[2];
            int[][] ints1={a1,a2};
            for(int[] x:ints1){
                x[0]=scanner.nextInt();
                x[1]=scanner.nextInt();
            }
            int s1=(Math.abs(a2[0]-a1[0])*Math.abs(a2[1]-a1[1]));
            int s2=(Math.abs(b2[0]-b1[0])*Math.abs(b2[1]-b1[1]));
            int sMax=s1>=s2?s1:s2;
            ArrayList<int[]> max=new ArrayList<>();
            ArrayList<int[]>  min=new ArrayList<>();
            if(s1>=s2){
                max.add(a1);
                max.add(a2);
                min.add(b1);
                min.add(b2);
            }
            else {
                max.add(b1);
                max.add(b2);
                min.add(a1);
                min.add(a2);
            }
            boolean det1=(min.get(0)[0]>=max.get(0)[0]&&min.get(0)[1]>=max.get(0)[1])
                    &&(min.get(0)[0]<=max.get(1)[0]&&min.get(0)[1]<=max.get(1)[1]);
            boolean det2=(min.get(1)[0]>=max.get(0)[0]&&min.get(1)[1]>=max.get(0)[1])
                    &&(min.get(1)[0]<=max.get(1)[0]&&min.get(1)[1]<=max.get(1)[1]);
            boolean det3=(min.get(0)[0]>=max.get(0)[0]&&min.get(1)[1]<=max.get(1)[1])
                    &&(min.get(0)[0]<=max.get(1)[0]&&min.get(1)[1]>=max.get(0)[1]);
            boolean det4=(min.get(1)[0]>=max.get(0)[0]&&min.get(0)[1]<=max.get(1)[1])
                    &&(min.get(1)[0]<=max.get(1)[0]&&min.get(0)[1]>=max.get(0)[1]);
            if(det1&&det2){
                s+=s1+s2-sMax;
                continue;
            }
            if(det1||det2||det3||det4){
                int[] p1=new int[2];
                int[] p2=new int[2];
                p1[0]=min.get(0)[0]>=max.get(0)[0]?min.get(0)[0]:max.get(0)[0];
                p1[1]=min.get(0)[1]>=max.get(0)[1]?min.get(0)[1]:max.get(0)[1];
                p2[0]=min.get(1)[0]<=max.get(1)[0]?min.get(1)[0]:max.get(1)[0];
                p2[1]=min.get(1)[1]<=max.get(1)[1]?min.get(1)[1]:max.get(1)[1];
                s+=(Math.abs(p2[0]-p1[0])*Math.abs(p2[1]-p1[1]));
            }
            if(s==s2) break;
        }
        System.out.println(s);
    }
}
